package com.zz.action;

import com.zz.utils.ShiroUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginAction {
    @RequestMapping("/login.do")
    public String login(String userName,String passWord){
        //得到shiro的主题对象
        Subject subject = ShiroUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(userName, passWord);
        try {
            subject.login(token);
        } catch (AuthenticationException e) {
            e.printStackTrace();
            System.out.println("认证失败");
            return "login";
        }

        return "forward:/listHouRent.do";
    }

    //登出
    @RequestMapping("/loginOut.do")
    public String loginOut(HttpServletRequest request){
        ShiroUtils.logout();
        return "login";
    }
}
